package com.daqian.cloud.client.demo.controller;

import com.daqian.chance.core.rest.RestResult;
import com.daqian.chance.redis.conf.RedisService;
import com.daqian.cloud.client.demo.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: daqian
 * @Date: 2019/4/22 21:14
 */
@RestController
@RequestMapping("demo1")
public class Demo1Controller {
    @Autowired
    private DemoService demoService;
    @Autowired
    private RedisService redisService;

    @GetMapping("getStr/{str}")
    public String getDemoStr(@PathVariable("str") String str) {
        return demoService.getDemoStr(str);
    }

    @GetMapping("test")
    public RestResult test() {
        System.out.println("这里demo1 test 了啊");
        try {
            Thread.sleep(12000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return RestResult.ok("test demo1");
    }

    @GetMapping("test2")
    public RestResult test2() {
        System.out.println("这里demo1 test22 了啊");
        return RestResult.ok("test22 demo1");
    }

    @GetMapping("redis")
    public RestResult redis(String key, String value) {
        redisService.setValue(key, value);
        Object value1 = redisService.getValue(key);
        System.out.println(value1);
        return RestResult.ok("test redis");
    }
}
